home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / DELPHI32 / COMPNENT / SAWIN95 / ANIMCTL.PAS next >
Pascal/Delphi Source File  |  1996-10-18  |  5KB  |  224 lines

  1. unit AnimCtl;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, CommCtrl;
  7.  
  8. type
  9.   TAnimation = class(TWinControl)
  10.   private
  11.     FAutoPlay   : Boolean;
  12.     FAVIFile    : String;
  13.     FCentered   : Boolean;
  14.     FFrom       : Integer;
  15.     FOpen       : Boolean;
  16.     FRepeat     : Integer;
  17.     FTo         : Integer;
  18.     FTransparent: Boolean;
  19.  
  20.     FOnStart    : TNotifyEvent;
  21.     FOnStop     : TNotifyEvent;
  22.     procedure SetAVIFile(Value: String);
  23.     procedure SetAutoPlay(Value: Boolean);
  24.     procedure SetCentered(Value: Boolean);
  25.     procedure SetTransparent(Value: Boolean);
  26.   protected
  27.     procedure Animate_Open(szName : PChar);
  28.     procedure Animate_Close;
  29.     procedure Animate_Play(FromFrame, ToFrame, RepeatCount: Integer);
  30.     procedure Animate_Stop;
  31.     procedure Animate_Seek(Frame : Integer);
  32.     procedure CreateParams(var Params: TCreateParams); override;
  33.     procedure CreateWnd; override;
  34.     procedure CNCommand(var Message: TWMCommand); message CN_COMMAND;
  35.     procedure CMColorChanged(var Message: TMessage); message CM_COLORCHANGED;
  36.   public
  37.     constructor Create(AOwner: TComponent); override;
  38.     destructor Destroy; override;
  39.     procedure Open;
  40.     procedure Close;
  41.     procedure Play;
  42.     procedure Stop;
  43.   published
  44.     property Align;
  45.     property AutoPlay: Boolean read FAutoPlay write SetAutoPlay default False;
  46.     property AVIFile: String read FAVIFile write SetAVIFile;
  47.     property Centered: Boolean read FCentered write SetCentered default True;
  48.     property Color;
  49.     property Enabled;
  50.     property FromFrame: Integer read FFrom write FFrom default 0;
  51.     property ToFrame: Integer read FTo write FTo default -1;
  52.     property Hint;
  53.     property ParentColor;
  54.     property ParentShowHint;
  55.     property PopupMenu;
  56.     property RepeatCount: Integer read FRepeat write FRepeat default -1;
  57.     property ShowHint;
  58.     property TabOrder;
  59.     property TabStop;
  60.     property Transparent: Boolean read FTransparent write SetTransparent default True;
  61.     property Visible;
  62.     property OnDragDrop;
  63.     property OnDragOver;
  64.     property OnEndDrag;
  65.     property OnEnter;
  66.     property OnExit;
  67.     property OnMouseDown;
  68.     property OnMouseMove;
  69.     property OnMouseUp;
  70.     property OnStartDrag;
  71.     property OnStart: TNotifyEvent read FOnStart write FOnStart;
  72.     property OnStop: TNotifyEvent read FOnStop write FOnStop;
  73.   end;
  74.  
  75. {$R ANIMCTL.RES}
  76.  
  77. implementation
  78.  
  79. constructor TAnimation.Create(AOwner: TComponent);
  80. begin
  81.   inherited Create(AOwner);
  82.   FTransparent := True;
  83.   FAutoPlay := False;
  84.   FCentered := True;
  85.   FFrom := 0;
  86.   FTo := -1;
  87.   FRepeat := -1;
  88. end;
  89.  
  90. destructor TAnimation.Destroy;
  91. begin
  92.   Close;
  93.   inherited Destroy;
  94. end;
  95.  
  96. procedure TAnimation.CreateParams(var Params: TCreateParams);
  97. begin
  98.   inherited CreateParams(Params);
  99.   CreateSubClass(Params, ANIMATE_CLASS);
  100.   if AutoPlay then Params.Style := Params.Style or ACS_AUTOPLAY;
  101.   if Centered then Params.Style := Params.Style or ACS_CENTER;
  102.   if Transparent then Params.Style := Params.Style or ACS_TRANSPARENT;
  103. end;
  104.  
  105. procedure TAnimation.CreateWnd;
  106. begin
  107.   inherited CreateWnd;
  108.   if AVIFile<>'' then Open;
  109. end;
  110.  
  111. procedure TAnimation.CNCommand(var Message: TWMCommand);
  112. begin
  113.   case Message.NotifyCode of
  114.     ACN_START: if Assigned(FOnStart) then FOnStart(Self);
  115.     ACN_STOP : if Assigned(FOnStop) then FOnStop(Self);
  116.   end;
  117. end;
  118.  
  119. procedure TAnimation.CMColorChanged(var Message: TMessage);
  120. begin
  121.   inherited;
  122.   RecreateWnd;
  123. end;
  124.  
  125. procedure TAnimation.SetAutoPlay(Value: Boolean);
  126. begin
  127.   if FAutoPlay<>Value then
  128.    begin
  129.      FAutoPlay := Value;
  130.      RecreateWnd;
  131.    end;
  132. end;
  133.  
  134. procedure TAnimation.SetCentered(Value: Boolean);
  135. begin
  136.   if FCentered<>Value then
  137.    begin
  138.      FCentered := Value;
  139.      RecreateWnd;
  140.    end;
  141. end;
  142.  
  143. procedure TAnimation.SetAVIFile(Value : String);
  144. begin
  145.   if FAVIFile<>Value then
  146.    begin
  147.      FAviFile := Value;
  148.      Close;
  149.      Repaint;
  150.      Open;
  151.    end;
  152. end;
  153.  
  154. procedure TAnimation.Animate_Play(FromFrame, ToFrame, RepeatCount: Integer);
  155. begin
  156.   if HandleAllocated then SendMessage(Handle, ACM_PLAY, WParam(RepeatCount),  LParam(MakeLong(FromFrame, ToFrame)));
  157. end;
  158.  
  159. procedure TAnimation.Animate_Stop;
  160. begin
  161.   if HandleAllocated then SendMessage(Handle, ACM_STOP, 0, 0);
  162. end;
  163.  
  164. procedure TAnimation.Animate_Seek(Frame : Integer);
  165. begin
  166.   Animate_Play(Frame, Frame, 1);
  167. end;
  168.  
  169. procedure TAnimation.Animate_Close;
  170. begin
  171.   Animate_Open(nil);
  172. end;
  173.  
  174. procedure TAnimation.Animate_Open(szName : PChar);
  175. begin
  176.   if HandleAllocated then SendMessage(Handle, ACM_OPEN, 0, LParam(szName));
  177. end;
  178.  
  179. procedure TAnimation.SetTransparent(Value: Boolean);
  180. begin
  181.   if FTransparent<>Value then
  182.    begin
  183.      FTransparent := Value;
  184.      RecreateWnd;
  185.    end;
  186. end;
  187.  
  188. procedure TAnimation.Play;
  189. begin
  190.   Animate_Play(FromFrame, ToFrame, RepeatCount);
  191. end;
  192.  
  193. procedure TAnimation.Stop;
  194. begin
  195.   Animate_Stop;
  196. end;
  197.  
  198. procedure TAnimation.Open;
  199. var
  200.   pFile : PChar;
  201. begin
  202.   try
  203.     Animate_Open(MakeIntResource(StrToInt(AVIFile)));
  204.   except
  205.     if Length(AVIFile)>0 then
  206.      begin
  207.        pFile := StrAlloc(Length(AVIFile)+1);
  208.        try
  209.          StrPCopy(pFile, AVIFile);
  210.          Animate_Open(pFile);
  211.        finally
  212.          StrDispose(pFile);
  213.        end;
  214.      end;
  215.   end;
  216. end;
  217.  
  218. procedure TAnimation.Close;
  219. begin
  220.   Animate_Close;
  221. end;
  222.  
  223. end.
  224.